#ifndef __CDRLOG__
#define  __CDRLOG__

#ifdef __Win32__
#pragma warning(disable:4786)
#endif


#include <stdio.h>
#include <vector>
#include "OSMutex.h"
#include "OSThread.h"
#include "OSTimer.h"

using namespace std;


struct cdrdata
{
	Char time[15];
	Char url[256];
	Char serverip[16];
	Char clientip[16];
	Char sessionid[11];
	Char useragent[256];
	Char progtype[3];
	Char starttime[15];
	Char endtime[15];
	Char playtime[11];
	Char filetime[21];
	Char sendpackets[11];
	Char sendbytes[21];
	Char filesize[21];
	Char qos[4];
	cdrdata()
	{
		memset(time,0,15);
		memset(url,0,256);
		memset(serverip,0,16);
		memset(clientip,0,16);
		memset(sessionid,0,11);
		memset(useragent,0,256);
		memset(progtype,0,3);
		memset(starttime,0,15);
		memset(endtime,0,15);
		memset(playtime,0,11);
		memset(filetime,0,21);
		memset(sendpackets,0,11);
		memset(sendbytes,0,21);
		memset(filesize,0,21);
		memset(qos,0,4);
	}
};

class CdrLogger:public OSTask
{
private:
	CdrLogger(const Char* v_CdrDir);
	~CdrLogger();
public:
	virtual Bool Initialize();
//	virtual Bool Destroy();
	static CdrLogger* GetInstance();
	static Bool DelInstance();
public:
	static Bool AddCdrRecord(cdrdata* v_CdrData);	
protected:
	virtual Bool Run();
	static Bool WriteCdr();
private:
	static CdrLogger* m_CdrLogger;
	static OSMutex m_Mutex_CdrList;
	static vector<cdrdata*> m_CdrList;
	static Char* m_CdrDir;
	Timer_T m_Timer;
};

extern CdrLogger* g_CdrLogger;

#endif

